package com.sywb.chuangyebao.view;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.sywb.chuangyebao.R;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 关于我们
 */
public class UserAboutActivity extends ActionbarActivity {

    @BindView(R.id.tv_version)
    TextView tvVersion;
    @BindView(R.id.tv_update)
    TextView tvUpdate;
    @BindView(R.id.tv_weixin)
    TextView tvWeixin;
//    @BindView(R.id.tv_about)
//    TextView tvAbout;

    @Override
    public int getLayoutId(Bundle bundle) {
        return R.layout.activity_user_about;
    }

    @Override
    public void initView(Bundle bundle) {
        super.initView(bundle);
        setTitle(R.string.about_us);

        tvVersion.setText("当前版本：V" + getLocalVersionName());
    }

    @Override
    public void initPresenter() {
    }

    @OnClick({R.id.tv_weixin, R.id.tv_update, R.id.tv_comment})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_weixin://微信官网
                advance(ContactUsActivity.class);
                break;
            case R.id.tv_update://版本更新
//                new PublicUtil(mActivity).checkVersion(2);
                break;
            case R.id.tv_comment:
                advance(WebActivity.class, "评分", "http://sj.qq.com/myapp/detail.htm?apkName=com.sywb.chuangyebao");
                break;
        }
    }

    /**
     * 获取本地软件版本号
     */
    public int getLocalVersion() {
        int localVersion = 0;
        try {
            PackageInfo packageInfo = getApplicationContext()
                    .getPackageManager()
                    .getPackageInfo(getPackageName(), 0);
            localVersion = packageInfo.versionCode;
//            LogUtil.d("TAG", "本软件的版本号。。" + localVersion);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return localVersion;
    }

    /**
     * 获取本地软件版本号名称
     */
    public String getLocalVersionName() {
        String localVersion = "";
        try {
            PackageInfo packageInfo = getApplicationContext()
                    .getPackageManager()
                    .getPackageInfo(getPackageName(), 0);
            localVersion = packageInfo.versionName;
//            LogUtil.d("TAG", "本软件的版本号。。" + localVersion);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return localVersion;
    }

}
